$(function(){

let form_button_item1=1;


  // 搜索栏
$("#search").click(function(){

    let search=document.getElementById("search-input");
    search.style.background="rgba(0,10,32,0.09)";
})

$("#search").blur(function(){

    let search=document.getElementById("search-input");
    search.style.background="rgba(0,10,32,0.05)";
})


// 标签栏搜索框
$("#search1").click(function(){

  let search=document.getElementById("search-input-2");
  search.style.background="rgba(0,10,32,0.09)";
})

$("#search1").blur(function(){

  let search=document.getElementById("search-input-2");
  search.style.background="rgba(0,10,32,0.05)";
})





// 轮播图控制

$("#arrow_right").click(function(){
  $("#arrow_left").css("text-decoration","none");
    $(".Shuffling_figure_1").animate({
        left:'-885px'
      });
      $(".Shuffling_figure_2").animate({
        left:'-590px'
      });
      $(".Shuffling_figure_3").animate({
        left:'-295px'
      });
      $(".Shuffling_figure_4").animate({
        left:'0px'
      });
      $(".Shuffling_figure_5").animate({
        left:'295px'
      });
      
})

// 轮播图控制
$("#arrow_left").click(function(){
    
      $("#arrow_left").css("text-decoration","none");
    $(".Shuffling_figure_1").animate({
        left:'0px'
      });
      $(".Shuffling_figure_2").animate({
        left:'295px'
      });
      $(".Shuffling_figure_3").animate({
        left:'590px'
      });
      $(".Shuffling_figure_4").animate({
        left:'885px'
      });
      $(".Shuffling_figure_5").animate({
        left:'1180px'
      });
      
})



// // 题单下拉动画
// $("#form-button-item1").click(function(){
  
  
//     if(form_button_item1==1){
//       $("#Suspension_1").focus();
//       $(".form-button").css("background-color","rgba(0,10,32,0.09)");
//       // 下拉样式动画
//       $("#Suspension_1").css("display","block");
//       $("#Suspension_1").css("transition","max-height 2s");
//       $("#Suspension_1").css("opacity","1");
//       $("#Suspension_1").css("max-height","500px");
//       $("#Suspension_1").css("height","auto");
//     }else{
//       $("#Suspension_1").css("border","none");
//       $(".form-button").css("background-color","rgba(0,10,32,0.05)");
//     // 下拉样式动画
//       $("#Suspension_1").css("opacity","0");
//       $("#Suspension_1").css("max-height","0px");
//       $("#Suspension_1").css("height","0");
//       $("#Suspension_1").css("transition","max-height 2s");  
//     }
//     form_button_item1=-form_button_item1;
     
   
    
   
// })

// $("#Suspension_1").blur(function(){

  
//     $("#Suspension_1").css("border","none");
//     $(".form-button").css("background-color","rgba(0,10,32,0.05)");
//     // 下拉样式动画
//     $("#Suspension_1").css("opacity","0");
//     $("#Suspension_1").css("max-height","0px");
//     $("#Suspension_1").css("height","0");
//     $("#Suspension_1").css("transition","max-height 2s");  
// })



// 分页栏
$(".page_form").click(function(){


  if($("#page_choose").css("display")=="none"){
    $(".page_choose").focus().css("display","block");
    $("#page_choose").focus();
  }else{
    $(".page_choose").css("display","none");
  }
})


$(".page_choose").blur(function(){
  $(".page_choose").css("display","none");
})

$(".page_a").click(function(){
    let page_show=document.getElementById("page_show");
    page_show.innerText=this.innerText;
  
})




});


function isLeapyear(year){
  return year%4==0 && year%100!=100 || year%400;
}

function getMaxDay(year,month){

  if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12){
          return 31;
      }else if(month==2){
          return isLeapyear(year)?29:28;
      }else{
          return 30;
      }
}
function get_week(year,month){
  var myDate = new Date(year,month-1,1);
  return myDate.getDay();

}


// 打印日历
window.onload=()=>{
  let str = "";//table tbody tr td ....  1到最大天数
  //获取年
  let year = new Date().getFullYear();
  let month = new Date().getMonth()+1;
  let nowYear = new Date().getFullYear();
  let nowmonth = new Date().getMonth()+1;
  let day=new Date().getDate();
  
  let hd_year=document.getElementById("year");
  hd_year.value=year;


  let hd_month=document.getElementById("month");
  hd_month.value=month;

  str+=`<table>
  <tr>
          <td>sun</td>
          <td>Mon</td>
          <td>Tue</td>
          <td>Wed</td>
          <td>Thu</td>
          <td>Fri</td>
          <td>Sat</td> 
  </tr>`;
  str+="<tr>";
       let count = 0;
       let daycount = 0;
       let week = get_week(year,month,1);
      

      
       for(let i=0;i<week;i++){
           str+="<td></td>";
           count++;
       }
       let max = getMaxDay(year,month);
       for(let i=1;i<=max;i++){
          daycount++;
          count++;
          if(day==daycount && month==nowmonth && year==nowYear){
              str+="<td style='background-color:rgba(0,122,255);border-radius: 50%;color:#fff'>"+i+"</td>";
          }else{
              str+="<td>"+i+"</td>";     
          }
      
           if(count==7){
               count = 0;
               str+="</tr>";
               str+="<tr>";
           }
       }
  
      str+="</table>";

      let div = document.getElementById("content");
      div.innerHTML = str;
}




// 上个月日历      
$("#cal_left").click(function(){
  let str = "";//table tbody tr td ....  1到最大天数
  let year=document.getElementById("year").value;
  let month=document.getElementById("month").value;
  let nowYear = new Date().getFullYear();
  let nowmonth = new Date().getMonth()+1;
  let day=new Date().getDate();
  month=month-1;

  if(month==0){
    month=12;
    year=year-1;
  }
  let hd_year=document.getElementById("year");
  hd_year.value=year;

  let hd_month=document.getElementById("month");
  hd_month.value=month;
  str+=`<table>
<tr>
        <td>sun</td>
        <td>Mon</td>
        <td>Tue</td>
        <td>Wed</td>
        <td>Thu</td>
        <td>Fri</td>
        <td>Sat</td> 
</tr>`;
str+="<tr>";
       let count = 0;
       let daycount = 0;
       let week = get_week(year,month,1);
      

      
       for(let i=0;i<week;i++){
           str+="<td></td>";
           count++;
       }
       let max = getMaxDay(year,month);
       for(let i=1;i<=max;i++){
          daycount++;
          count++;
          if(day==daycount && month==nowmonth && year==nowYear){
              str+="<td style='background-color:rgba(0,122,255);border-radius: 50%;color:#fff'>"+i+"</td>";
          }else{
              str+="<td>"+i+"</td>";     
          }
      
           if(count==7){
               count = 0;
               str+="</tr>";
               str+="<tr>";
           }
       }
  
      str+="</table>";

      let div = document.getElementById("content");
      div.innerHTML = str;
      let monthshow =document.getElementById("cal_label");
        
      monthshow.children[1].innerText=month+"月";
})


// 下个月日历
$("#cal_right").click(function(){
  let str = "";//table tbody tr td ....  1到最大天数
  let year=document.getElementById("year").value;
  let month=document.getElementById("month").value;
  let nowYear = new Date().getFullYear();
  let nowmonth = new Date().getMonth()+1;
  let day=new Date().getDate();
  month=month*1+1;
 
  if(month==13){
    month=1;
    year=year*1+1;
  }
  console.log(month)
  let hd_year=document.getElementById("year");
  hd_year.value=year;

  let hd_month=document.getElementById("month");
  hd_month.value=month;
  str+=`<table>
<tr>
        <td>sun</td>
        <td>Mon</td>
        <td>Tue</td>
        <td>Wed</td>
        <td>Thu</td>
        <td>Fri</td>
        <td>Sat</td> 
</tr>`;
str+="<tr>";
     let count = 0;
     let daycount = 0;
     let week = get_week(year,month,1);
        
     for(let i=0;i<week;i++){
         str+="<td></td>";
         count++;
     }
     let max = getMaxDay(year,month);
     for(let i=1;i<=max;i++){
        daycount++;
        count++;
        if(day==daycount && month==nowmonth && year==nowYear){
            str+="<td style='background-color:rgba(0,122,255);border-radius: 50%;color:#fff'>"+i+"</td>";
        }else{
            str+="<td>"+i+"</td>";     
        }
    
         if(count==7){
             count = 0;
             str+="</tr>";
             str+="<tr>";
         }
     }

    str+="</table>";

    let div = document.getElementById("content");
    div.innerHTML="";
    div.innerHTML = str;
    let monthshow =document.getElementById("cal_label");
        
    monthshow.children[1].innerText=month+"月";
})
